package Thread;

/**
 * Created by sunwei on 2017/9/30
 * Time:14:35
 */
public class ThreadDemo3 extends Thread {
    private String name;
    //构造方法
    public ThreadDemo3(String name) {
        super(name);
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程运行开始！");
        for(int i = 0; i <5 ; i++) {
            System.out.println("子线程"+name+"运行:"+i);
            try {
                sleep((int)Math.random()*10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(Thread.currentThread().getName()+"线程运行结束");
    }
}
